﻿using DreamCMS.BLL;
using DreamCMS.Entity;
using DreamCMS.Web.Admin;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.Admin.CatMgr
{
    public partial class Manage : AdminPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<CategoryInfo> catList = CategoryManager.GetCategoryList();
                rpCat.DataSource = catList;
                rpCat.DataBind();
            }
        }


        protected void lkbDelete_Command(object sender, CommandEventArgs e)
        {
            string deleteid = e.CommandArgument.ToString();
            if (CategoryManager.DeleteCategoryById(Convert.ToInt64(deleteid)))
            {
                rpCat.DataSource = CategoryManager.GetCategoryList();
                rpCat.DataBind();
                ClientScript.RegisterStartupScript(GetType(), "successdelete", "<script>alert('删除成功');</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "successdelete", "<script>alert('删除失败');</script>");
            }
        }

        protected void lkbUpdateSort_Click(object sender, EventArgs e)
        {
            List<CategoryInfo> catList = CategoryManager.GetCategoryList();
            foreach (CategoryInfo cat in catList)
            {
                long newSort = Convert.ToInt64(Request["sort[" + cat.CatId + "]"]);
                cat.Diplayorder = newSort;
            }
            if (!CategoryManager.UpdateCategory())
            {
                ClientScript.RegisterStartupScript(GetType(), "error", "<script>alert('更新失败');</script>");
                return;
            }
            ClientScript.RegisterStartupScript(GetType(), "error", "<script>alert('更新成功');</script>");
            rpCat.DataSource = CategoryManager.GetCategoryList();
            rpCat.DataBind();
        }
    }
}